package demo.android.com.myhttpdemo.okhttp.Rxjava;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import demo.android.com.myhttpdemo.okhttp.Rxjava.extra.HttpCallback;


/**
 * Created by Vya on 2018/2/1 0001.
 */

public class TestRetrofitActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.test_rxjava_activity);


        /*RetrofitClient.getServiceApi()
                .userLogin1("14726932514", "123456")
                // .subscribeOn().observeOn().subscribe()
                // Subscriber 封装一下
                // 注意：这里返回值是一个泛型，因此使用转换返回值泛型
                .compose(RetrofitClient.<UserInfo>transformer())
                // 注册完了要登录
                .subscribe(new BaseSubscriber<UserInfo>() {
                    @Override
                    protected void onError(String errorCode, String errorMessage) {
                        Log.e("wangyan","onError...."+errorMessage);
                    }

                    @Override
                    public void onNext(UserInfo userInfo) {
                        Log.e("wangyan","onNext....");
                        // toast(userInfo.toString());
                    }
                });*/

      /*  RetrofitClient.getServiceApi().userLogin("Darren1","940223")
                .enqueue(new Callback<Result<UserInfo>>() {
                    @Override
                    public void onResponse(Call<Result<UserInfo>> call, Response<Result<UserInfo>> response) {
                        Result<UserInfo> result = response.body();
                        if(result.isOk()){
                            //
                        }
                    }

                    @Override
                    public void onFailure(Call<Result<UserInfo>> call, Throwable t) {
                    }
                });*/
        RetrofitClient.getServiceApi().userLogin("Darren","123213")
                .enqueue(new HttpCallback<UserInfo>() {
                    @Override
                    public void onSucceed(UserInfo result) {
                        //这里就不需要判断成功了，来到这里必定是成功后的回调
                    }

                    @Override
                    public void onError(String code, String msg) {
                            //失败后的回调
                    }
                });
    }
}
